package pl.enigmatic.math.interpolation;

public class LinearInterpolator extends Interpolator {

	public LinearInterpolator(final double[] frames, final double[][] points) {
		super(frames, points);
	}

	public LinearInterpolator(final double[]... coord) {
		super(coord);
	}

	private static double calculate(final double left, final double right, final double t) {
		return t * right + (1 - t) * left;
	}

	@Override
	protected double[] getValue(final double alpha, final int rng, final double t) {
		final double res[] = new double[dimension];
		for (int i = 0; i < dimension; i++) {
			res[i] = calculate(points[rng][i], points[rng + 1][i], t);
		}
		return res;
	}

	public static class Single extends Interpolator.Single {

		public Single(final double[] frames, final double[] values) {
			super(frames, values);
		}

		@Override
		protected double getValue(final double alpha, final int rng, final double t) {
			return calculate(value(rng), value(rng + 1), t);
		}
	}
}
